﻿<%@ Page Title="设置用户类别权限" Language="C#" MasterPageFile="~/master/m.master" %>



<script runat="server"></script>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/system/GroupUser.css" />
    <link href="../assets/css/plugins/jsTree/style.min.css" rel="stylesheet" />
    <style>
 
    </style>
    <style>
        .system-box .right-side {
            width: 100%;
        }

        .system-box .right-content-box {
            overflow: hidden;
        }

        .content-container {
            background: #fff;
            width: 100%;
            padding: 8px;
            float: left;
            margin: 5px;
            border: 1px solid #dfdfdd;
        }

            .content-container.sp {
                width: calc(100% - 601px);
                border-right: 0;
            }

            .content-container .header-tips {
                margin-bottom: 15px;
            }

        .chooseArea {
            overflow: hidden;
        }

            .chooseArea .leftArea1,
            .chooseArea .rightArea1,
            .chooseArea .leftArea2,
            .chooseArea .rightArea2 {
                border: 1px solid #e5e6e7;
                float: left;
                overflow: auto;
            }

            .chooseArea .areaOutbox {
                float: left;
                width: 50%;
            }

        #btnSear {
            width: 80%;
        }

        #btnSearc {
            width: 20%;
        }

        .header-tips {
            text-align: center;
            font-size: 18px;
        }

        .border-1 {
            border-right: 1px solid #dcc7c7;
        }

        .pborder {
            border: 1px solid #dcc7c7;
            margin: 0;
            text-align: center;
            border-bottom: none;
            font-size: 16px;
        }

        .pborder1 {
            border-left: none;
        }
    </style>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="main" runat="Server">
    <div class="btns-container"></div>
    <div class="col-sm-6 border-1">
        <div class="right-content-box">
            <div class="content-container ">
                <div class="header-tips">设置用户类别权限</div>

                <div class="chooseArea">
                    <div class="areaOutbox">
                        <p class="pborder">待选用户</p>

                        <div class="leftArea1 leftArea1-width">
                            <div id="UserList"></div>
                        </div>
                    </div>
                    <div>
                        <p class="pborder pborder1">类别列表</p>
                        <input type="button" class="btn btn-default btn-primary " style="margin-left: 25px" value="全选" id="SelectAll" />
                        <input type="button" style="" class="btn btn-default btn-primary " value="反选" id="SelectTurn" />
                        <div class="leftArea1 leftArea1-1">
                            <div id="CategoryList"></div>
                        </div>
                    </div>
                </div>
                <div class="searchbox">
                    <div class="input-group">
                        <input type="text" class="form-control filter-users" id="btnSear" placeholder="请输入用户名">
                        <input class="btn btn-default btn-primary btn-filter-users" id="btnSearc" type="button" value="筛选"></input>
                    </div>
                    <!-- /input-group -->
                </div>
            </div>
        </div>
    </div>


</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/jsTree/jstree.min.js"></script>

    <script>
        var _AllCategoryList = [];
        $(document).ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //获取按钮
            commonUtil.loadBtnList(ModuleID, function () {
                rScroll();
            });
            //类别列表
            var GetAllCategoryList = function (callback) {
                Y.API2('UserCategoryManager', 'GetCategoryList', {}, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        callback(data);
                        _AllCategoryList = data;
                    }
                });
            }
            GetAllCategoryList(function (json) {
                //  CategoryList
                var newdata = $.map(json, function (obj) {
                    obj.id = obj.KindID + '';
                    //  obj.parent = "#";
                    obj.text = obj.KindName;
                    obj.state = {
                        opened: false,
                        selected: false,
                        disabled: false
                    };
                    obj.icon = "fa fa-folder text-info";
                    obj.li_attr = {
                        IsSelect: false
                    };
                    /* //子集 目前不使用 用的时候，需要调整
                      obj.children = $.map(obj.Childs, function (obj2) {
                          obj2.id = obj2.KindID+'';
                          obj2.text = obj2.KindName;
                          obj2.state = {
                              opened: false,
                              selected: false,
                              disabled: false
                          };
                          obj2.li_attr = {
                              IsSelect: false
                          };
                          obj2.icon = "fa fa-folder text-info";
                          obj2.children = $.map(obj2.Childs, function (obj3) {
                              obj3.id = obj3.KindID+'';
                              obj3.text = obj3.KindName;
                              obj3.li_attr = {
                                  isCategory: true
                              };
                              obj3.state = {
                                  selected: false
                              };
                              obj3.icon = "fa fa-file-text-o text-info";
                              return obj3;
                          });
                          return obj2;
                      });
                      */
                    return obj;
                });
                //  console.log(newdata);
                //加载待选列表
                $('#CategoryList').jstree({
                    'core': {
                        data: newdata
                    },
                    "checkbox": {
                        "keep_selected_style": false
                    },
                    "types": {
                        "default": {
                            "icon": "fa fa-folder text-info"
                        },
                        "child": {
                            "icon": "fa fa-file-text-o text-info"
                        }
                    },
                    "plugins": ["checkbox", "types"]

                }).on("ready.jstree", function () {


                })
            });

            //所有用户列表
            var GetAllUserList = function (callback) {
                //Y.API2('UserCategoryManager', 'GetUserList', {
                Y.API2('DataGroup', 'GetAllUserList', {
                    Keys: " "
                }, function (data) {
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        callback(data);
                    }
                    //  console.log(data)
                });
            }
            GetAllUserList(function (json) {
                var newdata = $.map(json, function (obj) {
                    obj.id = obj.UserID;
                    obj.parent = "#";
                    obj.text = obj.UserName;// + "【" + obj.UserNo + "】";
                    obj.state = {
                        opened: true,
                        selected: false
                    };
                    obj.icon = "fa fa-user text-info";
                    return obj;
                });
                //  console.log(newdata);

                //加载权限
                $('#UserList').jstree({
                    'core': {
                        data: newdata
                    },
                    "search": {
                        show_only_matches: true
                    },
                    "plugins": ["search"]
                }).on("changed.jstree", function (e, data) {
                    layer.msg('玩命加载中……', {
                        icon: 16,
                        shade: 0.01,
                        time: 0,
                        maxWidth: 200
                    });
                    //用户已选
                    GetUserCategoryList(data.selected[0], function (json) {
                        //后台加载已选择的数据
                        var newdata = $.map(json, function (obj) {
                            obj.id = parseInt(obj.KindID);
                            obj.text = obj.KindName;
                            obj.state = {
                                opened: false,
                                selected: true,
                                disabled: false
                            };
                            obj.icon = "fa fa-folder text-info";
                            obj.li_attr = {
                                IsSelect: true
                            };
                            //此处应该添加子集
                            return obj;
                        });
                        $('#CategoryList').jstree("deselect_all");
                        $('#CategoryList').jstree("select_node", newdata);
                    });
                });

            });
            //已选列表
            var GetUserCategoryList = function (UserID, callback) {
                Y.API2('UserCategoryManager', 'GetUserCategoryManagerList', {
                    UserID: UserID
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        callback(data);
                    }
                });
            }

            //提交
            $(document).on("click", "#SaveUserKindPer", function () {
                var userID = $('#UserList').jstree("get_selected");
                var CategoryList = $('#CategoryList').jstree("get_bottom_selected", true);
                if (Y.checkNull(userID)) {
                    swal("请选择用户", '', 'error');
                    return;
                }
                var _Categorylist = [];
                $.each(CategoryList, function (i, obj) {
                    // if (obj.li_attr.IsSelect) {
                    if (obj.state.selected)
                        _Categorylist.push(obj.id);
                });
                layer.msg('玩命加载中……', {
                    icon: 16,
                    shade: 0.01,
                    time: 0,
                    maxWidth: 200
                });

                Y.API2('UserCategoryManager', 'SaveCategoryManager', {
                    UserID: userID.toString(),
                    CategoryList: _Categorylist
                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                        layer.closeAll('dialog');
                    } else {
                        swal("提交成功！", '', 'success');
                    }
                })
            });

            //过滤 筛选用户 设置用户店铺权限
            $("#btnSearc").on("click", function () {
                var v = $("#btnSear").val();
                $('#UserList').jstree("search", v);
            });
            var to = false;
            $('#btnSear').on("keyup", function () {
                var v = $("#btnSear").val();
                if (to) {
                    clearTimeout(to);
                }
                to = setTimeout(function () {
                    $('#UserList').jstree("search", v);
                }, 250);
            });
            //自动高 DOCUMENT高减按钮栏+其它
            $(".chooseArea .leftArea1").height($(document).height() - (35 + 145));
            //全选
            $("#SelectAll").click(function () {
                var newdata = $.map(_AllCategoryList, function (obj) {
                    obj.id = obj.KindID + '';
                    obj.text = obj.KindName;
                    obj.state = {
                        opened: false,
                        selected: true,
                        disabled: false
                    };
                    obj.icon = "fa fa-folder text-info";
                    obj.li_attr = {
                        IsSelect: true
                    };
                    /* //子集 目前不使用 用的时候，需要调整
                      obj.children = $.map(obj.Childs, function (obj2) {
                          obj2.id = obj2.KindID+'';
                          obj2.text = obj2.KindName;
                          obj2.state = {
                              opened: false,
                              selected: false,
                              disabled: false
                          };
                          obj2.li_attr = {
                              IsSelect: false
                          };
                          obj2.icon = "fa fa-folder text-info";
                          obj2.children = $.map(obj2.Childs, function (obj3) {
                              obj3.id = obj3.KindID+'';
                              obj3.text = obj3.KindName;
                              obj3.li_attr = {
                                  isCategory: true
                              };
                              obj3.state = {
                                  selected: false
                              };
                              obj3.icon = "fa fa-file-text-o text-info";
                              return obj3;
                          });
                          return obj2;
                      });
                      */
                    return obj;
                });

                var item = $('#CategoryList').jstree("get_bottom_selected", true);
                //全选
                if (item.length == 0 || item.length != _AllCategoryList.length) {
                    $('#CategoryList').jstree("deselect_all");
                    $('#CategoryList').jstree("select_node", newdata);
                } else {
                    //全部
                    $('#CategoryList').jstree("deselect_all");
                }

            });
             //反选 SelectTurn
            $("#SelectTurn").click(function () {
                var newdata = $.map(_AllCategoryList, function (obj) {
                    obj.id = obj.KindID + '';
                    obj.text = obj.KindName;
                    obj.state = {
                        opened: false,
                        selected: false,
                        disabled: false
                    };
                    obj.icon = "fa fa-folder text-info";
                    obj.li_attr = {
                        IsSelect: false
                    };
                    /* //子集 目前不使用 用的时候，需要调整
                      obj.children = $.map(obj.Childs, function (obj2) {
                          obj2.id = obj2.KindID+'';
                          obj2.text = obj2.KindName;
                          obj2.state = {
                              opened: false,
                              selected: false,
                              disabled: false
                          };
                          obj2.li_attr = {
                              IsSelect: false
                          };
                          obj2.icon = "fa fa-folder text-info";
                          obj2.children = $.map(obj2.Childs, function (obj3) {
                              obj3.id = obj3.KindID+'';
                              obj3.text = obj3.KindName;
                              obj3.li_attr = {
                                  isCategory: true
                              };
                              obj3.state = {
                                  selected: false
                              };
                              obj3.icon = "fa fa-file-text-o text-info";
                              return obj3;
                          });
                          return obj2;
                      });
                      */
                    return obj;
                });
                var item = $('#CategoryList').jstree("get_bottom_selected", true);//获取已经被选中的
                $('#CategoryList').jstree("select_node", newdata); //先将全部选中
                $('#CategoryList').jstree("deselect_node", item); //将已经被选中的取消掉
            });
           
           
        });


    </script>
</asp:Content>



